//s属性
import request from '@/utils/request'
import type { AttrList, AttrData } from './type'
enum API {
  TATTR_URL = '/admin/product/attrInfoList',
  //添加
  ADDTATTR_URL = '/admin/product/saveAttrInfo',
  //二级
  UPDATETATTR_URL = '/admin/product/getAttrValueList/',
  //删除
  DELETETATTR_URL = '/admin/product/deleteAttr/',
  //   一级筛选
  CATEGORY1 = '/admin/product/getCategory1',
  CATEGORY2 = '/admin/product/getCategory2',
  CATEGORY3 = '/admin/product/getCategory3',
}
export const reqHasAttr = (
  category1Id: string,
  category2Id:   string,
  category3Id:  string,
) =>
  request.get<any, AttrList>(
    API.TATTR_URL +
      `${category1Id ? '/' + category1Id : ''}${
        category2Id ? '/' + category2Id : ''
      }${category3Id ? '/' + category3Id : ''}`,
  )

export const reqChild = (attrId: string) =>
  request.delete<any, any>(API.UPDATETATTR_URL + attrId)

export const reqAddAttr = (data: AttrData) => {
  //新增
  return request.post<any, any>(API.ADDTATTR_URL, data)
}

//删除
export const reqDeleteAttr = (attrId: string) =>
  request.delete<any, any>(API.DELETETATTR_URL + attrId)
export const getCategory1 = () => {
  // 一级
  return request.get<any, any>(API.CATEGORY1)
}

export const getCategory2 = (category1Id: string) => {
  // 一级
  return request.get<any, any>(API.CATEGORY2 + `/${category1Id}`)
}

export const getCategory3 = (category2Id: string) => {
  // 一级
  return request.get<any, any>(API.CATEGORY3 + `/${category2Id}`)
}
